/*
 * Copyright 2012 Chris Uyehara
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package com.chrisuyehara.vista.rpc.client;

import java.io.IOException;

import com.chrisuyehara.vista.rpc.client.RPCClient;

import com.chrisuyehara.vista.rpc.exceptions.LoginException;

import com.chrisuyehara.vista.rpc.parameters.LiteralParameter;

import com.chrisuyehara.vista.rpc.procedures.BlankRemoteProcedure;
import com.chrisuyehara.vista.rpc.procedures.Constants;

import org.junit.Assert;
import org.junit.Test;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * Class description
 *
 *
 * @version        v1.0, 2014-01-20
 * @author         Jim Horner
 */
public class DebugParametersITCase {

    /** Field description */
    private final Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * Method description
     *
     */
    @Test
    public void testMethod() {

        RPCClient c = new RPCClient(TestHarness.VISTA_HOSTNAME, TestHarness.VISTA_PORT);

        try {
            c.login(TestHarness.ACCESS_CODE, TestHarness.VERIFY_CODE);
            logger.debug(c.getContext());
        } catch (LoginException e) {
            Assert.fail("Login shouldn't have failed");
        } catch (IOException e) {
            Assert.fail("Shouldn't have an IO failure");
        }

        BlankRemoteProcedure r = new BlankRemoteProcedure("ORWPT LIST ALL");

        r.addParameter(new LiteralParameter("ACKERMAN"));
        r.addParameter(new LiteralParameter("1"));

//      BlankRemoteProcedure r = new BlankRemoteProcedure("ORWPT ID INFO");
//
//      r.addParameter(new LiteralParameter("100232"));

        try {

            c.call(r);

        } catch (IOException e) {

            Assert.fail("Shouldn't have an IO failure");

        } finally {

            c.disconnect();
        }

        logger.debug("Response {}", r.getResponse());
        logger.debug("Response Bytes {}", r.getResponse().getBytes());
    }
}
